package dianmobile.eistarandroid.ui.fragments;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import dianmobile.eistarandroid.R;
import dianmobile.eistarandroid.beans.MyNewsEntity;
import dianmobile.eistarandroid.ui.Adapter.MyActivityAdapter;
import dianmobile.eistarandroid.ui.activities.ViewPostActivity;
import dianmobile.eistarandroid.utils.ConstantsData;
import zrc.widget.SimpleHeader;
import zrc.widget.ZrcListView;

public class MyActivitiesFragment extends Fragment {

    private ZrcListView listView;
    private TextView noContentView;
    private List<MyNewsEntity> listData = new ArrayList<>();
    private MyActivityAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_my_activities, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstance) {
        super.onActivityCreated(savedInstance);

        noContentView = (TextView)getActivity().findViewById(R.id.tv_my_activities_no_DATA);
        listView = (ZrcListView)getActivity().findViewById(R.id.lv_my_activities_list);
        setPullToRefresh();

        adapter = new MyActivityAdapter(getActivity(), listData);
        listView.setAdapter(adapter);
        getNews();

        listView.setOnItemClickListener(new ZrcListView.OnItemClickListener() {
            @Override
            public void onItemClick(ZrcListView parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), ViewPostActivity.class);
                intent.putExtra(ConstantsData.EXTRA_FILE_NAME, listData.get(position).getFileName());
                intent.putExtra(ConstantsData.EXTRA_BOARD_NAME, listData.get(position).getBoardName());
                //TODO 传入userName或者时间用于跳转到该动态的地方
                getActivity().startActivity(intent);
                listData.remove(position);  //查看之后就删除该消息
                adapter.notifyDataSetChanged();
            }
        });
    }

    private void setPullToRefresh() {
        SimpleHeader header = new SimpleHeader(getActivity());
        header.setTextColor(0xff0066aa);
        header.setCircleColor(0xff33bbee);
        listView.setHeadable(header);

        listView.setOnRefreshStartListener(new ZrcListView.OnStartListener() {
            @Override
            public void onStart() {
                getNews();
            }
        });
    }

    private void getNews() {
    }

}
